package org.game.module.datingbo.trigger;

import com.xiaoleilu.hutool.date.DateUtil;
import org.game.db.bean.Player;
import org.game.db.bean.PlayerData;
import org.game.quartz.QuartzRefresher;
import org.utils.TimeUtil;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 处理上线城市约会触发及刷新
 * Created by fxf on 2018-3-19.
 */
public class QuartzCityDatingTrigger implements QuartzRefresher {

    Player player;

    public QuartzCityDatingTrigger(Player player) {
        this.player = player;
    }


    @Override
    public void quartzRefresh(Date date) {
        int triggerHour = DateUtil.hour(date,true);
        Date now = TimeUtil.getCalendarByHourMinute(triggerHour,0).getTime();
        if (!CityDatingTriggerManager.getJustRefreshHour().contains(triggerHour)) {
            Map<String, List<Integer>> timeFrameMap = CityDatingTriggerManager.getTimeFrame();
            //当前时间已经过了触发时间段
            if (timeFrameMap.size() == 0){
                return;
            }
            CityDatingTriggerManager.trigger(player, timeFrameMap, now);
        }
        CityDatingTriggerManager.refreshCityDating(player, now);
    }

    @Override
    public Date getLastRefreshTime() {
        PlayerData pd = player.getPlayerDatasFkPlayerId();
        return pd.getPlayerDataProxy().getDiscreteVO().getLastCityDatingFireTime();
    }

    @Override
    public void setLastRefreshTime(Date date) {
        PlayerData pd = player.getPlayerDatasFkPlayerId();
        pd.getPlayerDataProxy().getDiscreteVO().setLastCityDatingFireTime(date);
        pd.getPlayerDataProxy().save();
    }

    @Override
    public void update() {

    }
}